package com.zl.annotation.demo2.config;

import com.zl.annotation.pojo.User;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * 替换Spirng的配置文件的一个配置类
 *
 * @ClassName: MyConfig
 * @author: suke
 * @since: 2021/7/31 10:55
 */
@Configuration
//@ComponentScan({"com.zl.annotation.demo1.service","com.zl.annotation.demo1.dao"})  //扫描指定包下注解
@ComponentScan("com.zl.annotation.demo2")
public class MyConfig {

   //@Bean 替换bean标签,  标记在方法上
    // 把方法的返回值对象交给spring管理

    //这个方法, 在spring容器创建的时候, 去执行@Bean标记的方法
    @Bean("user1")
    public User createUser1(){
        System.out.println("aaa");
        User user = new  User();
        user.setId(1);
        user.setName("zhangsan");
        user.setPassword("123");
        return user;
    }

    @Bean("user2")
    public User createUser2(){
        User user = new  User();
        user.setId(2);
        user.setName("lisi");
        user.setPassword("123");
        return user;
    }
}
